package ReadData;
import com.opencsv.CSVReader;

import java.io.FileReader;
import java.io.IOException;
public class OpenCSV {
    public static Data loadDataset(String csvFile) {
        String[][] data = null;

        try (CSVReader reader = new CSVReader(new FileReader(csvFile))) {
            String[] header = reader.readNext();
            data = new String[1][header.length];
            data[0] = header;

            String[] row;
            int rowCount = 1;

            // 读取文件的每一行数据
            while ((row = reader.readNext()) != null) {
                String[][] newData = new String[rowCount + 1][header.length];
                System.arraycopy(data, 0, newData, 0, rowCount);
                data = newData;

                data[rowCount] = row;
                rowCount++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return new Data(data);
    }
}
